/**
 * nvue 的旋转动画
 * @param animation - 动画模块对象
 * @param iconEl - 元素
 * @param duration - 动画时间 单位毫秒
 */
export function nvueRotateAnimation(animation: any, iconEl: any, duration = 2000, state = true) {
  if (!iconEl || !state) {
    return;
  }

  animation.transition(
    iconEl,
    {
      styles: {
        transform: `rotate(360deg)`,
        transformOrigin: 'center center',
      },
      duration, // ms
      timingFunction: 'linear',
      delay: 0, // ms
    },
    () => {
      animation.transition(
        iconEl,
        {
          styles: { transform: `rotate(0deg)`, transformOrigin: 'center center' },
          duration: 0, // ms
          timingFunction: 'ease',
          delay: 0,
        },
        () => {
          nvueRotateAnimation(animation, iconEl, duration);
        }
      );
    }
  );
}
